package com.oauth.handler;

import io.micrometer.core.instrument.util.StringUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.springframework.stereotype.Component;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 自定义，用户退出成功后需要处理的handler
 */
@Component
@Slf4j
public class OAuthLogoutSuccessHandler implements LogoutSuccessHandler {


    @Override
    public void onLogoutSuccess(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse, Authentication authentication) throws IOException, ServletException {
        String redirect_uri = httpServletRequest.getParameter("redirect_uri");
        log.info("redirect_uri:{}",redirect_uri);
        if(StringUtils.isNotBlank(redirect_uri)){
            httpServletResponse.sendRedirect(redirect_uri);
        }
    }
}
